package com.heima.controller;

import com.heima.pojo.*;
import com.heima.service.UserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user-service")
@Api(value = "人员管理")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**用户分页查询
     *
     * @param user
     * @return
     */
    @GetMapping("/user/search")
    public PageBean getUserList(UserQueryParam user){
        PageBean list = userService.selectUserList(user);
        return list;
    }

    /**
     * 查询role
     * @return
     */
    @GetMapping("/role")
    public List<Role> getRoleList(){
        return userService.selectRoleList();
    }

    @PostMapping("/user")
    public Boolean addUser(@RequestBody UserPojo user){
        log.info("输入进来的user是:{}",user);
        return userService.addUser(user);
    }
    @PutMapping("/user/{userId}")
    public Boolean updateUser(@PathVariable int userId ,@RequestBody UserPojo user){
        log.info("要修改的内容为：{},id为：{}",user,userId);
        return userService.updateUser(userId,user);
    }
    @DeleteMapping("/user/{userId}")
    public Boolean deleteUserId(@PathVariable int userId){
        log.info("要删除的id为：{}",userId);
        return userService.deleteUser(userId);
    }

}
